﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// This class represents a mathematical identity matrix.
    /// </summary>
    [Serializable]
    public class IdentityMatrix : Matrix, IIdentityMatrix
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="IdentityMatrix"/> class.
        /// </summary>
        /// <param name="rows">The number of matrix rows.</param>
        public IdentityMatrix(int rows)
            : base(rows, rows)
        {
            for (int i = 0; i < rows; i++)
            {
                this.SetValueAtPosition(new MatrixPosition(i, i), 1);
            }
        }

        /// <summary>
        /// Determines whether the current matrix is an identity matrix.
        /// </summary>
        /// <returns>
        /// True if the current matrix is an identity matrix otherwise, false.
        /// </returns>
        public bool IsIdentityMatrix()
        {
            for (int i = 0; i < this.Rows; i++)
            {
                if (this.GetValueAtPosition(new MatrixPosition(i, i)) != 1)
                {
                    return false;
                }
            }

            return true;
        }
    }
}